home *** CD-ROM | disk | FTP | other *** search
- WiseStampLog("[wisestampsig.js] >>>>>");
- window.addEventListener("load", function (event) { wisestampsig.load(event) }, true);
- window.addEventListener("unload", function (event){ wisestampsig.unload(event) }, true);
-
- var wisestampsig =
- {
- PREFIX: "<!--WISESTAMP_SIG_START-->",
- SUFFIX: "<!--WISESTAMP_SIG_END-->",
- _prefs: null,
- _icon: null,
- _tempType: null,
- load: function (event) {},
- unload: function (event) {},
-
- get icon()
- {
- if (!this._icon)
- {
- this._icon = ToDataURI('chrome://wisestamp/skin/webmail_icon.png');
- }
- return this._icon;
- },
-
- get enabled()
- {
- return GetBoolValue("enabled");
- },
-
- get showButton()
- {
- WiseStampLog("[wisestampsig.js::showButton get] >>>>>");
- return this.enabled && !GetBoolValue("hidebuttons");
- },
-
- get autoInsertOnCompose()
- {
- return this.enabled && WiseStampPrefs.getBoolPref("autoinsert_compose",true,"autoinsert");
- },
-
- get autoInsertOnThread()
- {
- return this.enabled && WiseStampPrefs.getBoolPref("autoinsert_thread",true,"autoinsert");
- },
-
- get isFoxytunesInstalled()
- {
- return HasExtension("{463F6CA5-EE3C-4be1-B7E6-7FEE11953374}");
- },
-
- createSignature: function (aType)
- {
- WiseStampLog("[wisestampsig.js::createSignature] >>>>>");
- var sig = GetSignature(aType);
- if (sig)
- return this.PREFIX + sig + this.SUFFIX;
-
- return this.PREFIX + " " + this.SUFFIX;
- },
-
- insertSignature: function (iframe, isAuto, xPath)
- {
- WiseStampLog("[wisestampsig.js::insertSignature] >>>>>");
- if (!this.enabled)
- return;
-
- var body = iframe.contentDocument.body;
-
- var newMessage = true;
- if (body.innerHTML.length > 100)
- newMessage = false;
- else
- { // if > 100 - reply/forward. if < 100 - check how long the text only
- var text_body = strip_tags(body.innerHTML);
- newMessage = text_body.length < 5; // sometimes a couple of chars still exist
- }
-
- var atEnd = false;
- if (isAuto)
- {
- if ((newMessage && !this.autoInsertOnCompose) ||
- (!newMessage && !this.autoInsertOnThread))
- return;
-
- } else if (!isAuto)
- atEnd = true;
-
- var sig = this.createSignature(this._tempType);
- this._tempType = null;
- var pattern = new RegExp(this.PREFIX.replace("!", "\!") + "(.|\n)*" + this.SUFFIX.replace("!", "\!"));
- var inserted = false;
-
- if (body.innerHTML.match(pattern))
- {
- if (isAuto == false) // replace only if manually inserted
- {
- WiseStampLog("[wisestampsig.js::insertSignature] replacing existing signature");
- body.innerHTML = body.innerHTML.replace(pattern, sig.replace('$','$$$$'));
- }
-
- } else
- {
- if (xPath)
- {
- var match = evaluateXPath(iframe.contentDocument, xPath);
- if (match && match.length > 0)
- {
- WiseStampLog("[wisestampsig.js::insertSignature] mode II");
- var div = document.createElement("p");
- div.setAttribute("class", "wisestamp_sig");
- div.innerHTML = sig;
- match[0].parentNode.insertBefore(div, match[0]);
- inserted = true;
- }
- }
-
- if (!inserted && !atEnd)
- {
- WiseStampLog("[wisestampsig.js::insertSignature] mode III");
- body.innerHTML = '<br/><br/>' + sig + body.innerHTML;
- inserted = true;
-
- } else if (!inserted && atEnd)
- {
- WiseStampLog("[wisestampsig.js::insertSignature] mode IV");
- body.innerHTML = body.innerHTML + '<br/><br/>' + sig;
- inserted = true;
- }
- }
-
- WiseStampLog("[wisestampsig.js::insertSignature] <<<< inserted = " + inserted);
-
- if (inserted)
- WiseStampSigCreated();
- },
-
- initOptionsIcon: function (aEle)
- {
- WiseStampLog("[wisestampsig.js::initOptionsIcon] >>>>>");
-
- aEle.addEventListener("click", this, false);
- aEle.addEventListener("UpdateWisestampSignature", this, false);
- },
-
- handleEvent: function (event)
- {
- if (event.type == "click")
- {
- this.optionsIconClicked(event);
- } else if (event.type == "UpdateWisestampSignature")
- {
- WiseStampLog("[wisestampsig.js::handleEvent] event.type == UpdateWisestampSignature");
-
- if (this.refreshCallback)
- {
- WiseStampLog("[wisestampsig.js::handleEvent] " + event.target.getAttribute("sigtype"));
- this._tempType = event.target.getAttribute("sigtype");
- this.refreshCallback();
- }
- }
- },
-
- optionsIconClicked: function (event)
- {
- var evt = document.createEvent("MouseEvents");
- evt.initMouseEvent("ShowWisestampMenu", true, false, window, event.detail, event.screenX, event.screenY, event.clientX, event.clientY, event.ctrlKey, event.altKey, event.shiftKey, event.metaKey, event.button, event.relatedTarget);
-
- var canceled = !event.target.dispatchEvent(evt);
- }
- }
-
- function evaluateXPath(aNode, aExpr)
- {
- var xpe = new XPathEvaluator();
- var nsResolver = xpe.createNSResolver(aNode.ownerDocument == null ? aNode.documentElement : aNode.ownerDocument.documentElement);
- var result = xpe.evaluate(aExpr, aNode, nsResolver, 0, null);
- var foundxp = [];
- var res;
- var idx = 0;
- while ((res = result.iterateNext()))
- foundxp.push(res);
-
- return foundxp;
- }